<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>审核列表(供应商)</title>
    <link rel="stylesheet" type="text/css" href="/manager/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="/manager/easyui/themes/icon.css">
    <script type="text/javascript" src="/manager/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="/manager/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript">
        //工具栏
        var toolbar = [{
            text: '添加',
            iconCls: 'icon-edit',
            handler: function () {
                $('#dd').dialog('open');
            }
        }];
        $(function () {
            $('#booklist').datagrid({
                title: '审核列表',
                iconCls: 'icon-save',
                url: '/manager/examine/supplierFindAll',
                columns: [
                    [
                        {field: 'title', title: '审核标题', width: 100, align: 'center'},
                        {field: 'info', title: '审核备注', width: 200, align: 'center'},
                        {
                            field: 'flag',
                            title: '审核状态',
                            width: 80,
                            align: 'center',
                            formatter: function (value, row, index) {
                                return value == "1" ? "通过" : "没通过";
                            }
                        },
                        {
                            field: 'book',
                            title: '书籍详情',
                            width: 200,
                            align: 'center',
                            formatter: function (value, row, index) {
                                return "<a href='#' onclick='showBook(" + row.id + ")'>查看</a>";
                            }
                        }
                    ]],
                toolbar: toolbar,
                pagination: true,//表示在datagrid设置分页
                pageSize: 5,
                singleSelect: true,
                pageList: [5, 10, 20]
            });

            //初始化查询栏
            $("#submit_search").linkbutton({iconCls: 'icon-search', plain: true})
                .click(function () {
                    let data = {};
                    let bookname = $("#search-book-name").val();
                    let isbn = $("#search-book-isbn").val();
                    if (bookname != "") {
                        data.bookname = bookname;
                    }
                    if (isbn != "") {
                        data.isbn = isbn;
                    }
                    $('#booklist').datagrid("reload", data);
                });

            //初始化修改窗口
            $('#dd').dialog({
                title: 'My Dialog',
                width: 700,
                height: 500,
                closed: true,
                cache: false,
                href: '',
                modal: true,
                iconCls: 'icon-save',
                buttons: [{
                    text: '提交',
                    iconCls: 'icon-ok',
                    handler: function () {
                        addBook();
                    }
                }, {
                    text: '关闭',
                    handler: function () {
                        $('#dd').dialog("close");
                    }
                }]
            });

            $("#show-book-id").dialog({
                title: 'My Dialog',
                width: 700,
                height: 500,
                closed: true,
                cache: false,
                modal: true,
            })

            // 添加时 显示isbn查询信息
            $("input", $("#search-book-by-isbn").next("span")).blur(function () {
                let isbn = this.value;
                if (isbn.length == 10 || isbn.length == 13) {
                    $.post("/manager/book/findByIsbn", {isbn: isbn}, rs => {
                        if (rs.status == 200) {
                            $("#add-book-name").textbox("setValue", rs.data.bookname);
                            $("#add-book-price").textbox("setValue", rs.data.price);
                            $("#add-book-group-price").textbox("setValue", rs.data.groupprice);
                            $("#add-book-bookintroduce").textbox("setValue", rs.data.bookintroduce);

                            let imgurl = rs.data.imgurl;
                            imgurl = imgurl && imgurl.indexOf("http") == 0 ? imgurl : "/manager/" + imgurl;
                            $("#add-img-id").attr("src", imgurl);
                        } else {
                            console.log(rs.msg);
                            alert(rs.msg);
                        }
                    });
                } else {
                    alert("isbn格式不对");
                }
            });
        });

        //显示单本审核书籍信息信息
        function showBook(id) {
            console.log("显示书籍信息" + id);
            $("#show-book-id").dialog("open");

            $.post("/manager/examine/findOne", {id: id}, rs => {
                console.log(rs);
                $("#show-book-name").textbox("setValue", rs.data.book.bookname);
                $("#show-book-isbn").textbox("setValue", rs.data.book.isbn);
                $("#show-book-price").textbox("setValue", rs.data.book.price);
                $("#show-book-num").textbox("setValue", rs.data.number);
                $("#show-book-group-price").textbox("setValue", rs.data.book.groupprice);
                $("#show-book-bookintroduce").textbox("setValue", rs.data.book.bookintroduce);
                $("#show-book-authorintroduce").textbox("setValue", rs.data.book.authorintroduce);


                let imgurl = rs.data.book.imgurl;
                imgurl = imgurl.indexOf("http") == 0 ? imgurl : "/manager/" + imgurl;
                $("#show-img-id").attr("src", imgurl);
            })
        }

        // 添加书籍
        function addBook() {
            let data = new FormData($("#ff")[0]);
            console.log(data);
            $.ajax({
                url: "/manager/examine/add",
                type: "post",
                data: data,
                // dataType: "json",
                processData: false,
                contentType: false,
                success: function (rs) {
                    console.log(rs);
                    alert(rs.msg);
                }
            });

        }


        // XXXXXX 先调用函数,再改变值 滞后
        function findBookByIsbn() {
            let isbn = $("#search-book-by-isbn").textbox("getValue");
            console.log("isbn :" + isbn);
            if (isbn.length == 10 || isbn.length == 13) {
                console.log("查找数据");
            } else {
                alert("isbn格式不对");
            }
        }

    </script>
</head>
<body>
<form name="searchform" method="post" action="" id="searchform">
    <td width="70" height="30"><strong>审核查询：</strong></td>
    <td height="30">
        <input type="text" name="keyword" id="search-book-name" size=20 placeholder="书籍名称"/>
        <input type="text" name="keyword" id="search-book-isbn" size=20 placeholder="ISBN"/>
    </td>
    <td>
        <button type="button" id="submit_search">查询</button>
    </td>
</form>
<table id="booklist"></table>
<div id="dd">
    <div align="center" style="margin-top: 30px">
        <form id="ff" method="post">
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="bookname" style="width:50%"
                       id="add-book-name"
                       data-options="label:'书籍名称:',required:true">
            </div>
            <div style="margin-bottom:20px">
                <!--                <input class="easyui-textbox" name="isbn" style="width:50%" id="search-book-by-isbn"-->
                <!--                       data-options="label:'ISBN:',required:true,events:{blur:findBookByIsbn}"> -->
                <input class="easyui-textbox" name="isbn" style="width:50%"
                       id="search-book-by-isbn"
                       data-options="label:'ISBN:',required:true">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="price" style="width:50%"
                       id="add-book-price"
                       data-options="label:'单价:',required:true,">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="number" style="width:50%"
                       data-options="label:'数量:',required:true">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="groupprice" style="width:50%"
                       id="add-book-group-price"
                       data-options="label:'团购价:',required:true">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="layout" style="width:50%" data-options="label:'版次:',required:true">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="register" style="width:50%"
                       data-options="label:'册数:',required:true">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="weight" style="width:50%" data-options="label:'重量:',required:true">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="bookintroduce" style="width:50%;height:60px"
                       id="add-book-bookintroduce"
                       data-options="label:'书籍简介:',multiline:true">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" name="authorintroduce" style="width:50%;height:60px"
                       id="add-book-authorintroduce"
                       data-options="label:'作者简介:',multiline:true">
            </div>
            <div style="margin-bottom:20px">
                封面图片:&nbsp;&nbsp;&nbsp;&nbsp; <input name="img" type="file"/>
            </div>
            <div style="margin-bottom:20px">
                <img id="add-img-id" alt="没有对应图片" src=""></img>
            </div>
        </form>
    </div>
</div>


<div id="show-book-id">
    <div align="center" style="margin-top: 30px">
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" name="bookname" style="width:50%"
                   id="show-book-name"
                   data-options="label:'书籍名称:',required:true">
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" name="isbn" style="width:50%"
                   id="show-book-isbn"
                   data-options="label:'ISBN:',required:true">
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" name="price" style="width:50%"
                   id="show-book-price"
                   data-options="label:'单价:',required:true">
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" name="number" style="width:50%"
                   id="show-book-num"
                   data-options="label:'数量:',required:true,validType:'email'">
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" name="groupprice" style="width:50%"
                   id="show-book-group-price"
                   data-options="label:'团购价:',required:true">
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" name="layout" style="width:50%" data-options="label:'版次:',required:true">
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" name="register" style="width:50%"
                   data-options="label:'册数:',required:true">
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" name="weight" style="width:50%" data-options="label:'重量:',required:true">
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" name="bookintroduce" style="width:50%;height:60px"
                   id="show-book-bookintroduce"
                   data-options="label:'书籍简介:',multiline:true">
        </div>
        <div style="margin-bottom:20px">
            <input class="easyui-textbox" name="authorintroduce" style="width:50%;height:60px"
                   id="show-book-authorintroduce"
                   data-options="label:'作者简介:',multiline:true">
        </div>
        <div style="margin-bottom:20px">
            <img id="show-img-id" alt="没有对应图片" src=""></img>
        </div>
    </div>
</div>

</body>
</html>